using OhioState.Graphics;
using OhioState.Graphics.Proxy;
using OhioState.Physics;

namespace OhioState.Graphics.OpenGL
{
    public class RigidBodyGL : OpenGLObject, IDrawable
    {
        private RigidBody _rigidBodyProxy;
        #region IDrawable Members
        private BoundingBox _bBox;
        public IBoundingVolume BoundingVolume
        {
            get { return _bBox; }
            set
            {
                BoundingBox bBox = value as BoundingBox;
                if (bBox != null)
                {
                    _bBox = (BoundingBox)bBox.Clone();
                }
            }
        }
      
        private IMaterial _material;
        public IMaterial Material
        {
            get { return _material; }
            set { _material = value; }
        }

        public void Render(IRenderPanel panel)
        {
            Tao.OpenGl.Gl.glPushMatrix();
            Tao.OpenGl.Gl.glTranslatef(_rigidBodyProxy.Position.x, _rigidBodyProxy.Position.y, _rigidBodyProxy.Position.z);
            if(_drawableObj == null)
                _drawableObj = panel.ResourceManager.GetItem(_rigidBodyProxy.Drawable) as IDrawable;
            if (_drawableObj != null)
                _drawableObj.Render(panel);
            Tao.OpenGl.Gl.glPopMatrix();
        }
        #endregion
        private IDrawable _drawableObj;
        internal RigidBodyGL(RigidBody proxyObj)
            : base(proxyObj)
        {
            _rigidBodyProxy = proxyObj;
        }
    }
}
